package org.inspursc.s0517.health.evaluation.converter;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import org.inspursc.s0517.health.evaluation.dto.SurveyAnswerDTO;
import org.inspursc.s0517.health.evaluation.dto.SurveyAnswerDateDTO;
import org.inspursc.s0517.health.evaluation.dto.SurveyAnswerGradeDTO;
import org.inspursc.s0517.health.evaluation.entity.SurveyAnswer;
import org.springframework.beans.BeanUtils;

/**
 * @author B_Dream
 * @date 2018/6/20 10:26
 */
public class SurveyAnswerConverter {

    public static SurveyAnswer converter(SurveyAnswerDTO anDTO) {
        SurveyAnswer an = new SurveyAnswer();
        BeanUtils.copyProperties(anDTO, an);

        return an;
    }


    public static SurveyAnswerDTO converter(SurveyAnswer an) {
        SurveyAnswerDTO anDTO = new SurveyAnswerDTO();
        BeanUtils.copyProperties(an, anDTO);

        return anDTO;
    }

    public static SurveyAnswerDateDTO converterDateStr(SurveyAnswer an) {
        SurveyAnswerDateDTO anDTO = new SurveyAnswerDateDTO();
        BeanUtils.copyProperties(an, anDTO);
        JSONObject jsonObject= JSON.parseObject(an.getAntoComputeJson());
        anDTO.setAntoComputeJson(jsonObject);
        return anDTO;
    }

    public static SurveyAnswerGradeDTO converterToGrade(SurveyAnswer answer) {
        SurveyAnswerGradeDTO answerDTO = new SurveyAnswerGradeDTO();
        BeanUtils.copyProperties(answer, answerDTO);
        return answerDTO;
    }


}
